clear all;close all;clc
%% variable initialization and read from the log file.
nullx = [1 ];starx = [1 ];sharx = [1 ];compx=[1 ];
nnullx = [1 ];nstarx = [1 ];nsharx = [1 ];ncompx=[1 ];splot = 1;


a = dlmread('socialNetwork10',',',1);

%%      extracting the data from the log files.
randseed = a(:,1); n = a(:,2); expt = a(:,3); n_repeat = a(:,4); c = a(:,5);
delta = a(:,6); density = a(:,7); mean_acts = a(:,8); mean_iterations = a(:,9);
mean_utility = a(:,10);

    null = a(:,11);      star = a(:,12);      shared = a(:,13);     complete = a(:,14);
nearnull = a(:,15);  nearstar = a(:,16);  nearshared = a(:,17); nearcomplete = a(:,18);
all_type = a(:,11:18);
%%
for p = [10]      % number of players
    for q = [1 2 3 4]       % num of experiments
        for r = [0.0 0.35 0.7]        % density 
       ix = find(n == p & expt == q & density == r);
    all_t = all_type(ix,:);
for i = 1:length(ix)
    [ixx ix1] = (max(all_t(i,:)));      % obtaining the max value and storing the index in ix1 and creating the index vector respectively
    if(ix(i) == 1213) 
     ix1
    end
    if ix1 == 1;          nullx = [nullx; ix(i)];  end
    if ix1 == 2;          starx = [starx; ix(i)];  end
    if ix1 == 3;          sharx = [sharx; ix(i)];  end
    if ix1 == 4;          compx = [compx; ix(i)];  end
    if ix1 == 5;         nnullx = [nnullx; ix(i)];  end
    if ix1 == 6;         nstarx = [nstarx; ix(i)];  end
    if ix1 == 7;         nsharx = [nsharx; ix(i)];  end
    if ix1 == 8;         ncompx = [ncompx; ix(i)];  end
end

%% Plots of the obtained index
figure(1);subplot(4,4,splot);
plot(c(nullx),delta(nullx),'s','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',10);grid on;hold on
plot(c(starx),delta(starx),'s','MarkerEdgeColor','r','MarkerFaceColor','r','MarkerSize',10);grid on;hold on
plot(c(sharx),delta(sharx),'s','MarkerEdgeColor','b','MarkerFaceColor','b','MarkerSize',10);grid on;hold on
plot(c(nnullx),delta(nnullx),'s','MarkerEdgeColor','y','MarkerFaceColor','y','MarkerSize',10);grid on;hold on
plot(c(nstarx),delta(nstarx),'s','MarkerEdgeColor','m','MarkerFaceColor','m','MarkerSize',10);grid on;hold on
plot(c(nsharx),delta(nsharx),'s','MarkerEdgeColor','c','MarkerFaceColor','c','MarkerSize',10);grid on;hold on
plot(c(ncompx),delta(ncompx),'*','MarkerEdgeColor','g','MarkerFaceColor','g','MarkerSize',18);grid on;hold on
plot(c(compx),delta(compx),'s','MarkerEdgeColor','k','MarkerFaceColor','k','MarkerSize',10);grid on;hold on
%% 

% Reinitializing all the variables to empty vector
nullx = [ ];starx = [ ];sharx = [ ];compx=[ ];
nnullx = [ ];nstarx = [ ];nsharx = [ ];ncompx=[ ];

splot = splot+1;
if (rem(splot, 4) == 0) splot = splot+1; end;
clear ix
% % z = zeros(21,21);
% % for i = 1:21
% %     for j = 1:21
% %         idx = (i-1)*21+j;
% %         [r c] = max(all_t(idx,:));
% %         z(idx) = c;
% %     end
% % end
% % z = flipdim(z,1);
% % figure(2);image(z*25);
        end
    end
end
subplot(441);legend('null', 'star', 'shared', 'near null', 'near star', 'near shared', ...
        'near complete', 'complete', 'Orientation','horizontal')
figure(1);subplot(4,4,1);ylabel({'Unilateral Add';'Unilateral Del'},'Rotation',0,...
        'HorizontalAlignment','Right');
figure(1);subplot(4,4,5);ylabel({'Unilateral Add';'Mutual Del'},'Rotation',0, ...
        'HorizontalAlignment','Right');
figure(1);subplot(4,4,9);ylabel({'Mutual Add';'Unilateral Del'},'Rotation',0, ...
        'HorizontalAlignment','Right');
figure(1);subplot(4,4,13);ylabel({'Mutual Add';'Mutual Del'},'Rotation',0, ...
        'HorizontalAlignment','Right');

figure(1);subplot(4,4,1);title('0')
figure(1);subplot(4,4,2);title('0.35')
figure(1);subplot(4,4,3);title('0.7')
set(figure(1),'OuterPosition',[100 100 647 634])
